const app = new Vue({
  el: "#app",
  data: {
    books: [
      {
        id: 1,
        name: '《算法导论》',
        date: '2006-09',
        price: 85.00,
        count: 1
      },
      {
        id: 2,
        name: '《UNIX编程艺术》',
        date: '2006-02',
        price: 59.00,
        count: 1
      },
      {
        id: 3,
        name: '《编程思想》',
        date: '2008-10',
        price: 39.00,
        count: 1
      },
      {
        id: 4,
        name: '《代码大全》',
        date: '2006-03',
        price: 128.00,
        count: 1
      }
    ]
  },
  methods: {
    btnClick(index) {
      this.books.splice(index, 1)
    },
    // getShowPrice(price){
    //   return '￥'+price.toFixed(2)
    // },
  },
  computed: {
    totalPrice() {
      // let totalPrice = 0
      // for (let i = 0; i < this.books.length; i++) {
      //   totalPrice += (this.books[i].price*this.books[i].count)
      // }
      // return totalPrice
      return this.books.reduce(function (preValue, book) {
        return preValue + book.price * book.count
      }, 0)
    }
  },
  filters: {
    showPrice(price) {
      return '￥' + price.toFixed(2)
    }
  }
})